from django.db import models

from user.models import UserModel
from utils.BaseModel import BaseModel


# Create your models here.
class Coupon(BaseModel):
    name = models.CharField(max_length=100, verbose_name="优惠券名称")
    price=models.DecimalField(max_digits=10,decimal_places=2,verbose_name="优惠券价格")
    condition=models.FloatField(verbose_name="优惠券使用条件",default=0)
    starttime=models.DateTimeField(verbose_name="优惠券开始时间")
    endtime=models.DateTimeField(verbose_name="优惠券结束时间")
    number=models.IntegerField(default=100,verbose_name="优惠券数量")
    coudesc=models.CharField(max_length=100,verbose_name="优惠券描述")
    class Meta:
        db_table="coupon"
    def __str__(self):
        return self.name

class UserCoupon(BaseModel):
    user=models.ForeignKey(UserModel,on_delete=models.CASCADE,verbose_name="用户")
    coupon=models.ForeignKey(Coupon,verbose_name="优惠券",on_delete=models.CASCADE)
    class Meta:
        db_table="usercoupon"

